<%--
  Created by IntelliJ IDEA.
  User: zmjha
  Date: 2020/6/16
  Time: 20:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib  prefix="c"  uri="http://java.sun.com/jsp/jstl/core"%>

<html>
<head>
    <title>主页面</title>
</head>
<body>
<button type="button" onclick="addInfo()">添加</button>
<form action="getInfo">
    <input type="text" name="search">
    <input type="submit">提交搜索
</form>

<table border="1">
    <tr>
        <th>id</th>
        <th>user_id</th>
        <th>性别</th>
        <th>名字</th>
        <th>电话</th>
        <th>操作</th>
    </tr>

        <c:forEach items="${infolist }" var="info">
           <tr>
               <td>${info.uid}</td>
               <td>${info.user_id}</td>
               <td>${info.sex}</td>
               <td>${info.rname}</td>
               <td>${info.phone}</td>
               <td>
                   <button type="button" onclick="updateInfo(${info.uid})">更改</button>
                   <button type="button" onclick="del(${info.uid})">删除</button>
               </td>
           </tr>

        </c:forEach>
<hr>
    总共${pageInfo.total}记录，总共${pageInfo.pages}页
    <a href="getInfo?pageNum=${pageInfo.prePage}">上一页</a>  <a href="getInfo?pageNum=1">第一页</a><a href="getInfo?pageNum=2">第二页</a><a href="getInfo?pageNum=3">第三页</a><a href="getInfo?pageNum=${pageInfo.nextPage}">下一页</a>
</table>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
    function addInfo() {
        location.href="toUpdate"
    }
    function updateInfo(id) {
        var uid=0;
        if(id!=undefined){
            uid=id;
         location.href="toUpdate?uid="+uid;
        }
    }
    function del(id) {
        var uid=0;
        if(id!=undefined) {
            uid = id;
            $.ajax({
                url:"del",
                type:"post",
                data:{"uid":uid},
                success:function(obj){
                    var data=JSON.parse(obj);
                    if(data.code==1){
                       alert(data.mes);
                       location.reload()
                    }else {
                        alert(data.mes)
                        location.reload()
                    }
                }
            })
        }
    }
</script>
</html>
